package com.wenhao.newfeature.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Wenhao Tong
 * @create 2021-07-30 12:45
 */
public class Test {

    private static Student student;

    public static void main(String[] args) throws NoSuchFieldException {
        student = new Student();
        student.setAge(10);
        student.setSex("男");
        student.setName("Aisen Chen");
        Map<String,Object> map = new HashMap<>();
        // getField()只可以获取public的属性
        // getDeclaredField()可以获取包括private的属性，但是不可以获取继承的属性
        Field[] fields = student.getClass().getDeclaredFields();
        for (Field field : fields) {
            FieldName fieldName = student.getClass().getDeclaredField(field.getName()).getDeclaredAnnotation(FieldName.class);
            System.out.print(fieldName.value() + ":" + student.getClass().getDeclaredField(field.getName()));
        }
    }
}
